/**
 * Created by smp on 2017/4/14.
 */
var modelPath=ROOT_PATH+'/observation/statisticsAnalysis/';
function toDate(){
    var date=new Date();
    var year=date.getFullYear();
    var month=date.getMonth()+1;
    if(month<10)
        month="0"+month;
    var day=date.getDate();
    if(day<10)
        day="0"+day;
    return year+"-"+month+"-"+day;
}
$(function () {
    var ate=new Date();
    $("#beginTime").datebox('setValue', ate.getFullYear()+"-01-01");
    $("#endTime").datebox('setValue', toDate());
    $('#dg1').treegrid({
        striped: true,
        idField:'id',
        treeField:'name',
        fit: true,
        singleSelect: true,
        fitColumns: true,
        toolbar: '#toolbar',
        url: modelPath + 'unitList.shtml',
        queryParams:{
            beginTime:$("#beginTime").datebox('getValue'),
            endTime:$("#endTime").datebox('getValue')
        },
        columns: [[
            {field: 'name', title: '部门名称', width: 100},
            {field: 'allCount', title: '合计', width: 80},
            {field: 'actCount', title: '不安全行为', width: 100},
            {field: 'stateCount', title: '不安全状态', width: 100},
            {field: 'safeActCount', title: '推荐安全行为', width: 100}
        ]]
    });

    $('#btn_clear').on("click", function () {
        $('#tb1').form('reset');
    });
    $('#btn_search').on("click", function () {
        reLoadData()
    });
});






/**
 * 重新加载表格
 */
function reLoadData() {
    $('#dg1').datagrid('clearSelections');
    var queryParams1 = $('#tb1').serializeJson();
    var queryParams2 = $('#tb2').serializeJson();
    var queryParams = $.extend(queryParams1,queryParams2);
    $('#dg1').treegrid('options').queryParams = queryParams;
    $("#dg1").treegrid('reload');
}
